//
//  DDNavigationController.m
//  DingDongZP
//
//  Created by Jyh on 16/3/13.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDNavigationController.h"

@interface DDNavigationController ()

@end

@implementation DDNavigationController

/**
 *  在类第一次创建的时候设置主题
 */
+(void)initialize{
    
    //1.设置导航栏的主题
    UINavigationBar *bar = [UINavigationBar appearance];
    
    //设置字体
    [bar setTitleTextAttributes:@{NSFontAttributeName :[UIFont systemFontOfSize:16], NSForegroundColorAttributeName : [UIColor whiteColor]}];
    //系统返回箭头颜色
    [bar setTintColor:[UIColor whiteColor]];
    
    //设置导航栏Item主题
    UIBarButtonItem *item = [UIBarButtonItem appearance];
   
    //设置左右BarButtonItem的颜色
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName : [UIFont systemFontOfSize:15]} forState:UIControlStateNormal];
    //设置不可用字体颜色
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName : UIColorFromRGB(0xacdba6)} forState:UIControlStateDisabled];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 设置右滑返回上一层手势有效
    self.interactivePopGestureRecognizer.enabled = YES;
    
    self.interactivePopGestureRecognizer.delegate = nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/**
 *  重写push方法，设置统一的返回按钮
 *
 *  @param viewController
 *  @param animated
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //隐藏底部工具条
//    viewController.hidesBottomBarWhenPushed = YES;
    //统一设置左边返回按钮箭头
    if (self.viewControllers.count > 0) {
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(backToLastVC)];
    }

    
    [super pushViewController:viewController animated:animated];
}

- (void) backToLastVC{
    //添加按钮返回事件
    if (_tapBarItem != nil) {
        self.tapBarItem();
    }
    
    [self popViewControllerAnimated:YES];
}

//
//- (void) tapBackNavBlock:(void (^)())block {
//    _tapBarItem = block;
//}
- (void) tapBackNavBlock:(tapNavBlock)block {
    _tapBarItem = block;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
